<?php
load('extend');//加载扩展函数
/**
 * 请求HTTP数据
 * @param  [type] $url     完整URL地址
 * @param  string $params  POST参数
 * @param  string $method  提交方式GET、POST
 * @param  array  $header  Header参数
 */
function http($url, $params = '', $method = 'GET', $header = array(), $agent = array()){
	$method = strtoupper($method);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	if($method == 'POST'){
		curl_setopt($ch, CURLOPT_POST, TRUE);
		if($params != '')curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
	}
	curl_setopt($ch, CURLOPT_URL, $url);
	if(!empty($agent)){
		curl_setopt($ch, CURLOPT_PROXY, $agent['ip']); //代理服务器地址
		curl_setopt($ch, CURLOPT_PROXYPORT, $agent['port']); //代理服务器端口
		//http代理认证帐号，username:password的格式
		if($agent['username'] && $agent['password']){
			curl_setopt($ch, CURLOPT_PROXYUSERPWD, $agent['username'] . ":" . $agent['password']); 
			curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式
		}
	}
	var_dump($url);
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36 2 3 SE 2.X MetaSr 1.0');
	$response    = curl_exec($ch);
	$http_status = curl_getinfo($curl,CURLINFO_HTTP_CODE);
	var_dump($http_status);
	curl_close($ch);

	return $response;
}
/**
 * 字符串中间用星号表示
 * @param  [type] $str 字符串
 */
function str_middle_asterisk($str){
	//判断是否包含中文字符  
	if(preg_match("/[\x{4e00}-\x{9fa5}]+/u", $str)) {  
		//按照中文字符计算长度  
		$len = mb_strlen($str, 'UTF-8');  
		//echo '中文';
		if($len >= 3){  
			//三个字符或三个字符以上掐头取尾，中间用*代替  
			$str = mb_substr($str, 0, 1, 'UTF-8') . '*' . mb_substr($str, -1, 1, 'UTF-8');  
		} elseif($len == 2) {  
			//两个字符  
			$str = mb_substr($str, 0, 1, 'UTF-8') . '*';  
		}  
	} else {  
		//按照英文字串计算长度  
		$len = strlen($str);  
		//echo 'English';  
		if($len >= 3) {  
			//三个字符或三个字符以上掐头取尾，中间用*代替  
			$str = substr($str, 0, 1) . '*' . substr($str, -1);  
		} elseif($len == 2) {  
			//两个字符  
			$str = substr($str2, 0, 1) . '*';  
		}  
	}
	return $str;
}
function generate_doc($title, $content, $save_path = ''){
	import("PHPWord", 'Public/Class/Other', '.php');
	// New Word Document
	$PHPWord = new \PHPWord();

	// New portrait section
	$section = $PHPWord->createSection();
	$PHPWord->addFontStyle('rtStyle', array('name'=>'华文中宋', 'size'=>18));

	$PHPWord->addParagraphStyle('ptStyle', array('align'=>'center'));
	$PHPWord->addFontStyle('rpStyle', array('bold'=>true,'name'=>'华文仿宋', 'size'=>12));
	$PHPWord->addParagraphStyle('ppStyle', array('align'=>'left', 'spaceAfter'=>100, 'spacing'=>120));

	$PHPWord->addFontStyle('rwStyle', array('name'=>'华文仿宋', 'size'=>12));
	$PHPWord->addFontStyle('rswStyle', array('name'=>'华文仿宋', 'size'=>12,'color'=>'ff0000'));

	$PHPWord->addParagraphStyle('pwStyle', array('align'=>'left', 'spaceAfter'=>100, 'spacing'=>120));
	$PHPWord->addFontStyle('pStyle', array('underline'=>'single','name'=>'华文仿宋', 'size'=>12));
	$PHPWord->addFontStyle('bStyle', array('bold'=>true,'name'=>'华文仿宋', 'size'=>12));

	$section->addText($title, 'rtStyle', 'ptStyle');
	$section->addTextBreak(2);

	$section->addText('　　(声明：1、生成后格式为Word，无Logo、无水印；2、本声明文字可在下载后自行删除；3、生成过程中的提示，仅是基于通常情况下合同条款的示范，不能视为是米律的指导意见；4、合同文本及具体条款，不是标准及最终法律文本，仅供参考，米律建议根据实际情况，在法律专业人士的指导下进行修改后才使用，米律就在线生成的合同不承担任何法律责任。)','rswStyle', 'pwStyle');


	$content = preg_replace("/ style=\".*?\"/si", "", $content);
	//去除<p>
	$content = str_replace('<p>', '', $content);

	//去除&nbsp;
	$content = str_replace('&nbsp;', ' ', $content);
	$content = str_replace('&ldquo;', '“', $content);
	$content = str_replace('&rdquo;', '”', $content);
	$content = str_replace('<strong>', '', $content);
	$content = str_replace('</strong>', '', $content);
	$content = str_replace('<div>', '', $content);
	$content = str_replace('</div>', '</p>', $content);
	foreach (explode('</p>', $content) as $text) {
		$text = strip_tags($text);
		$section->addText($text, 'rwStyle', 'ppStyle');
	}
	$save_path = $save_path ? $save_path : './Uploads/make_word/';
	$filename  = $save_path . md5($title . uniqid()) . '.docx';
	// Save File
	$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
	$objWriter->save($filename);

	return $filename;
}

/**
* 根据HTML代码获取word文档内容
* 创建一个本质为mht的文档，该函数会分析文件内容并从远程下载页面中的图片资源
* 该函数依赖于类WordMake
* 该函数会分析img标签，提取src的属性值。但是，src的属性值必须被引号包围，否则不能提取
*
* @param string $content HTML内容
* @param string $absolutePath 网页的绝对路径。如果HTML内容里的图片路径为相对路径，那么就需要填写这个参数，来让该函数自动填补成绝对路径。这个参数最后需要以/结束
* @param bool $isEraseLink 是否去掉HTML内容中的链接
*/
function word_make( $content , $absolute_path = "" , $is_erase_link = true ){
	import("Wordmaker", 'Public/Class/Other');
	$mht = new Wordmaker();
	if ($isEraseLink){
		$content = preg_replace('/<a\s*.*?\s*>(\s*.*?\s*)<\/a>/i' , '$1' , $content);   //去掉链接
	}
	$images  = array();
	$files   = array();
	$matches = array();
	//这个算法要求src后的属性值必须使用引号括起来
	if ( preg_match_all('/<img[.\n]*?src\s*?=\s*?[\"\'](.*?)[\"\'](.*?)\/>/i', $content, $matches ) ){
		$arrPath = $matches[1];
		for ( $i=0; $i<count($arrPath); $i++){
			$path    = $arrPath[$i];
			$imgPath = trim( $path );
			if ( $imgPath != "" ){
				$files[] = $imgPath;
				if( substr($imgPath,0,7) == 'http://'){
					//绝对链接，不加前缀
				}
				else{
					$imgPath = $absolutePath.$imgPath;
				}
				$images[] = $imgPath;
			}
		}
	}
	$mht->AddContents("tmp.html", $mht->GetMimeType("tmp.html"), $content);
	for ( $i = 0; $i < count($images); $i++){
		$image = $images[$i];
		if ( @fopen($image , 'r') ){
			$imgcontent = @file_get_contents( $image );
			if ( $content ){
				$mht->AddContents($files[$i], $mht->GetMimeType($image), $imgcontent);
			}
		}
		else{
			echo "file:" . $image . " not exist!<br />";
		}
	}
return $mht->GetFile();
}
/**
 * 生成URL
 * @param string $url        地址
 * @param string $vars       参数
 * @param string $router_url 路由地址
 */
function URL($url = '', $vars = '', $router_url = ''){
	if(C('URL_ROUTER_ON') && $router_url){
		$new_url = U((strpos($router_url, '/') === 0 ? '' : '/') . $router_url);
	}else{
		$new_url =  U($url, $vars);
	}

	// 判断是否有检查权限方法
	$layer = C('DEFAULT_M_LAYER');
	$class =   parse_res_name('Role', $layer);
	import($class);
	$is_acl = 1;//有权限
	if(class_exists($class)){
		$role_model = D('Role');
		// var_dump($role_model);exit;
		if(method_exists($role_model, 'url_is_acl')){
			$is_acl = $role_model->url_is_acl($new_url, 1);
		}
	}
	return $new_url . ($is_acl ? '' : '#delete-link');
}
/**
 * 获取支付类型描述
 * @param  [type] $pay_type 支付类型
 */
function get_pay_type_desc($pay_type){
	if(!$pay_type){
		return '';
	}
	$pay_desc = '系统交易';
	$pay_type_list = C('pay_type_list');
	foreach ($pay_type_list as $rs) {
		if($rs['code'] == $pay_type){
			$pay_desc = $rs['title'];
		}
	}
	return $pay_desc;
}
/**
 * 获取类型描述
 * @param  [type] $key  KEY
 * @param  [type] $type 类型
 */
function get_type_desc($key, $type){
	$type_desc = C($type);
	$desc = $type_desc[$key];

	return $desc;
}
/**
 * 生成订单号
 */
function generate_order_sn(){
	//随机生成2位数
	$chars = str_repeat('12356789', 3);
	$chars = str_shuffle($chars);

	$order_sn = substr($chars, 0, 2).substr(date('YmdHis'), 2) . \Org\Util\TPString::randString(2, 1);
	return $order_sn;
}
/**
 * 路由规则分页处理
 * @param  [type] $html 分页HTML代码
 */
function router_page($html){
	if(C('URL_ROUTER_ON')){
		$list = C('USER_MENU_LIST');
		foreach ($list as $rs) {
			$search[]  = $rs['url'];
			$replace[] = $rs['router_url'];
			foreach ($rs['list'] as $row) {
				$search[]  = $row['url'];
				$replace[] = $row['router_url'];
				foreach ($row['list'] as $rw) {
					$search[]  = $rw['url'];
					$replace[] = $rw['router_url'];
				}
			}
		}
		$search[]  = '.html';
		$replace[] = '';

		$search[]  = '/p/';
		$replace[] = '?p=';

		$page_html = str_replace($search, $replace, $html);
	}

	return $page_html ? $page_html : $html;
}
/**
 * 获取配置
 * @param  string $name 配置名
 * @param  string $type 配置类型
 */
function Conf($name='',$type='system'){
	$where['type'] = $type;
	$where['name'] = $name;
	$val = D('Config')->where($where)->getField('val');
	return trim($val);
}

/**
 * 机构价格计算
 * @param  [type] $price 原价
 * @return [type]        机构价格
 */
function org_price_calc($price){
	$org_price = 1000;

	if($price <= 100){
		$org_price = 150;
	}
	elseif ($price > 100 && $price <= 200) {
		$org_price = 300;
	}
	elseif ($price > 200 && $price <= 300) {
		$org_price = 500;
	}
	elseif ($price > 300 && $price <= 400) {
		$org_price = 600;
	}
	elseif ($price > 400 && $price <= 500) {
		$org_price = 800;
	}
	elseif ($price > 500) {
		$org_price = 1000;
	}
	return $org_price;
}
/**
 * 开始结束日期文字说明
 * @param  string $start_date [开始日期]
 * @param  string $end_date   [结束日期]
 */
function start_end_date_desc($start_date='',$end_date=''){
	$date_desc = '';
	if($start_date){
		$date_desc = $start_date;
	}
	if($start_date&&$end_date){
		$date_desc .= '至';
	}
	if($start_date&&!$end_date){
		$date_desc .= '至'.date('Y-m-d');
	}
	if(!$start_date&&$end_date){
		$date_desc .= '截止';
	}
	if($end_date){
		$date_desc .= $end_date;
	}
	$date_desc = $date_desc?$date_desc:'全部';
	return $date_desc;
}
/**
 * 密码加密
 * @param  string $username 用户名
 * @param  string $password 明文密码
 * @param  string $code     密钥
 * @return string           加密后密码
 */
function password_md5($username='',$password='',$code='suncco_'){
	$newpassword = md5($code.md5($password).md5($username));
	return $newpassword;
}
/**
 * 密码加密（一次MD5加密）
 * @param  string $username 用户名
 * @param  string $password 一次MD5加密
 * @param  string $code     密钥
 * @return string           加密后密码
 */
function password_md5_one($username='',$password='',$code='suncco_'){
	$newpassword = md5($code.($password).md5($username));
	return $newpassword;
}
function echo_json($data=''){
	header('Content-Type:text/json; charset=UTF-8');
	$data = json_encode($data);
	exit($data);
}


function search_work($data='',$keyword=''){
	return str_replace($keyword, '<span style="color:red">'.$keyword.'</span>', $data);
}


/**
 * xml to array ,only for php5
 */
function xml_to_array($xml){
	$xml_parser = xml_parser_create(); 
	if(!xml_parse($xml_parser,$xml,true)){ 
		xml_parser_free($xml_parser); 
		return false;
	}else { 
		$array = (array)(@simplexml_load_string($xml,'SimpleXMLElement',LIBXML_NOCDATA)); 
		if($array){
			foreach ($array as $key=>$item){ 
				$array[$key] = struct_to_array((array)$item); 
			} 
		}
	}
	return $array; 
}
function struct_to_array($item) {
	if(!is_string($item)) { 
		$item = (array)$item; 
		foreach ($item as $key=>$val){ 
		  $item[$key] = struct_to_array($val); 
		} 
	} 
	return $item;
}
/**************************************************************
   *
   *    使用特定function对数组中所有元素做处理
   *    @param  string  &$array     要处理的字符串
   *    @param  string  $function   要执行的函数
   *    @return boolean $apply_to_keys_also     是否也应用到key上
   *    @access public
   *
 *************************************************************/
function arrayRecursive(&$array, $function, $apply_to_keys_also = false)
{
	static $recursive_counter = 0;
	if (++$recursive_counter > 1000) {
		die('possible deep recursion attack');
	}
	foreach ($array as $key => $value) {
		if (is_array($value)) {
			arrayRecursive($array[$key], $function, $apply_to_keys_also);
		} else {
			$array[$key] = $function($value);
		}
 
		if ($apply_to_keys_also && is_string($key)) {
			$new_key = $function($key);
			if ($new_key != $key) {
				$array[$new_key] = $array[$key];
				unset($array[$key]);
			}
		}
	}
	$recursive_counter--;
}
 
/**************************************************************
 *
 *    将数组转换为JSON字符串（兼容中文）
 *    @param  array   $array      要转换的数组
 *    @return string      转换得到的json字符串
 *    @access public
 *
 *************************************************************/
function json($array) {
	arrayRecursive($array, 'urlencode', true);
	$json = json_encode($array);
	return urldecode($json);
}
/**
 * 简单对称加密算法之加密
 * @param String $string 需要加密的字串
 * @param String $skey 加密EKY
 * @author Anyon Zou <cxphp@qq.com>
 * @date 2013-08-13 19:30
 * @update 2014-01-21 28:28
 * @return String
 */
 function encode($string = '', $skey = 'suncco') {
	$skey = str_split(base64_encode($skey));
	$strArr = str_split(base64_encode($string));
	$strCount = count($strArr);
	foreach ($skey as $key => $value) {
		$key < $strCount && $strArr[$key].=$value;
	}
	return str_replace('=', 'O0O0O', join('', $strArr));
 }
 /**
 * 简单对称加密算法之解密
 * @param String $string 需要解密的字串
 * @param String $skey 解密KEY
 * @author Anyon Zou <cxphp@qq.com>
 * @date 2013-08-13 19:30
 * @update 2014-01-21 28:28
 * @return String
 */
 function decode($string = '', $skey = 'suncco') {
	$skey = str_split(base64_encode($skey));
	$strArr = str_split(str_replace('O0O0O', '=', $string), 2);
	$strCount = count($strArr);
	foreach ($skey as $key => $value) {
		$key < $strCount && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
	}
	return base64_decode(join('', $strArr));
 }
/**
 * 字符截取 支持UTF8/GBK
 * @param $string
 * @param $length
 * @param $dot
 */
function str_cut($string, $length, $dot = '...') {
	$strlen = strlen($string);
	if($strlen <= $length) return $string;
	$string = str_replace(array(' ','&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), array('∵',' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string);
	$strcut = '';
	if(strtolower('utf-8') == 'utf-8') {
		$length = intval($length-strlen($dot)-$length/3);
		$n = $tn = $noc = 0;
		while($n < strlen($string)) {
			$t = ord($string[$n]);
			if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
				$tn = 1; $n++; $noc++;
			} elseif(194 <= $t && $t <= 223) {
				$tn = 2; $n += 2; $noc += 2;
			} elseif(224 <= $t && $t <= 239) {
				$tn = 3; $n += 3; $noc += 2;
			} elseif(240 <= $t && $t <= 247) {
				$tn = 4; $n += 4; $noc += 2;
			} elseif(248 <= $t && $t <= 251) {
				$tn = 5; $n += 5; $noc += 2;
			} elseif($t == 252 || $t == 253) {
				$tn = 6; $n += 6; $noc += 2;
			} else {
				$n++;
			}
			if($noc >= $length) {
				break;
			}
		}
		if($noc > $length) {
			$n -= $tn;
		}
		$strcut = substr($string, 0, $n);
		$strcut = str_replace(array('∵', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), array(' ', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), $strcut);
	} else {
		$dotlen = strlen($dot);
		$maxi = $length - $dotlen - 1;
		$current_str = '';
		$search_arr = array('&',' ', '"', "'", '“', '”', '—', '<', '>', '·', '…','∵');
		$replace_arr = array('&amp;','&nbsp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;',' ');
		$search_flip = array_flip($search_arr);
		for ($i = 0; $i < $maxi; $i++) {
			$current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
			if (in_array($current_str, $search_arr)) {
				$key = $search_flip[$current_str];
				$current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
			}
			$strcut .= $current_str;
		}
	}
	return $strcut.$dot;
}

//==================地图相关函数==================
/**
 * 范围搜索算法
 * $lng 经度
 * $lat 纬度
 */
function range_search($lng,$lat,$distance=1000){
	$EARTH_RADIUS = 6378.137;
	$distance = $distance/1000;//米
	$dlng = 2*asin(sin($distance/(2*$EARTH_RADIUS))/cos($lat));
	$dlng = rad2deg($dlng);
	$dlat = $distance / $EARTH_RADIUS;
	$dlat = rad2deg($dlat);
	$data['lng'][0] = $lng+$dlng;
	$data['lng'][1] = $lng-$dlng;
	$data['lat'][0] = $lat+$dlat;
	$data['lat'][1] = $lat-$dlat;
	return $data;
}
//计算两坐标距离
function get_distance($radLat1,$radLat2,$type=3) {
	$data = array();
	if($radLat1&&$radLat2){
		$radLat1 = explode(',',$radLat1);
		$radLat2 = explode(',',$radLat2);
		$x1 = $radLat1[0];
		$y1 = $radLat1[1];
		$x2 = $radLat2[0];
		$y2 = $radLat2[1];
		$latx1 = rad($x1);
		$latx2 = rad($x2);
		$a = $latx1-$latx2;
		$b = rad($y1)-rad($y2);
		$s = 2*asin(sqrt(pow(sin($a/2),2)+cos($latx1)*cos($latx2)*pow(sin($b/2),2)));
		$s = $s*6378.137;
		$s = round($s*10000*1000)/10000;//米
		
		if($s>=1000){
			$distance = sprintf('%.2f',$s/1000).'km';
		}else{
			$distance = sprintf('%d',$s).'m';
		}
	}
	return $distance;
}
function rad($val){
	$PI = 3.14159265358979;
	return $val*$PI/180.0;
}
/**
 * 根据出生日期计算年龄
 * @param  [type] $birth 出生年月日
 */
function age($birthday) {
	if(!$birthday || $birthday == '0000-00-00'){
		return 0;
	}
	$age = date('Y', time()) - date('Y', strtotime($birthday));  
	if (date('m', time()) == date('m', strtotime($birthday))){  
		if (date('d', time()) > date('d', strtotime($birthday))){  
			$age++;  
		}  
	}elseif (date('m', time()) > date('m', strtotime($birthday))){  
		$age++;
	}
	return $age;
}
/**
 * 与当前时间差多少文字说明
 * @param  [type] $btime [description]
 * @return [type]        [description]
 */
function time_ago_desc($btime){  
	$result = '';  
	$time =time() - $btime ;  
	if($time < 60){  
		$result = $time.'秒前';  
	}  
	else if($time < 1800){  
		$result = floor($time/60).'分钟前';  
	}else if($time < 3600){  
		$result = '半小时前';  
	}else if($time < 86400){  
		$result = floor($time/3600).'小时前';  
	}else{  
		$zt = strtotime(date('Y-m-d 00:00:00'));  
		$qt = strtotime(date('Y-m-d 00:00:00',strtotime("-1 day")));  
		$st = strtotime(date('Y-m-d 00:00:00',strtotime("-2 day")));  
		$bt = strtotime(date('Y-m-d 00:00:00',strtotime("-7 day")));  
		if( $btime < $bt){  
			$result = date('Y-m-d H:i:s', $btime);
			// $result = floor($time/86400).'天前';
		}else if($btime < $st){  
			$result = floor($time/86400).'天前';  
		}else if($btime < $qt){  
			$result = "前天".date('H:i', $btime);  
		}else{  
			$result = '昨天'.date('H:i', $btime);  
		}
	}
	return $result;  
}
/**
 * 时间类型说明(上午、下午、晚上)
 * @param  string $time 10:10
 */
function time_type_desc($time=''){
	$hour = date('H',strtotime($time));
	if($hour >= 6 && $hour < 13){
		$desc = '上午';
	}
	else if($hour >= 13 && $hour <= 19){
		$desc = '下午';
	}else{
		$desc = '晚上';
	}
	return $desc;
}
/**
 * 计算多维数组的交集
 * @param  [type] $array [description]
 * @return [type]        [description]
 */
function array_intersect_arr($array){
	$arr_num = count($array);
	if($arr_num == 1){
		return $array[0];
	}
	$id_list = array();
	foreach ($array as $key => $value) {
		$_str_arr[] = implode(',', $value);
	}
	$_all_str = implode(',', $_str_arr);
	$_all_srt_arr = explode(',', $_all_str);
	//处理老师ID交集
	$str_count = array_count_values($_all_srt_arr);
	foreach ($str_count as $id => $count) {
		if($count > 1){
			$id_list[] = $id;
		}
	}
	foreach ($id_list as $key => $id) {
		$i = 0;
		foreach ($array as $_in_array) {
			if(in_array($id, $_in_array)){
				$i++;
			}
		}
		if($i != $arr_num){
			unset($id_list[$key]);
		}
	}
	return $id_list;
}
/**
 * 生成高德静态地图URL
 * @param  [type]  $location 坐标x,y
 * @param  integer $width    宽度
 * @param  integer $height   高度
 * @param  integer $zoom     缩放1-17
 */
function amap_map_img_url($location,$width=400,$height=200,$zoom=12){
	if(!$location){
		return '';
	}
	$location = explode(',', $location);
	$point_x  = $location[0];
	$point_y  = $location[1];
	$key = C('amap_key');
	$url = 'http://restapi.amap.com/v3/staticmap?scale=2&location='.$point_x.','.$point_y.'&zoom='.$zoom.'&size='.$width.'*'.$height.'&markers=mid,0xFF0000,A:'.$point_x.','.$point_y.'&key='.$key;
	return $url;
}
/**
 * 地址解析(地址转坐标)
 * @param  string $address 地址
 */
function qq_geocoder_xy($address){
	$key     = 'NWZBZ-5MAWJ-6KBFB-F3O5B-XMRN2-4NB5X';
	$address = urlencode($address);

	$url  = 'http://apis.map.qq.com/ws/geocoder/v1/?address='.$address.'&key='.$key;
	$data = file_get_contents($url);
	$json = json_decode($data,true);
	$location = $json['result']['location'];
	return $location;
}
/**
 * 设置图片宽高
 * @param  string $images_url 原图片URL
 * @param  string $width      宽度
 * @param  string $height     高度
 * @return string             图片URL
 */
function img($images_url='',$width='',$height='', $ext = 'jpg'){
	if($width && $height){
		$images_url = $images_url ? $images_url : DOMAIN_PATH . '/Public/Images/default.png';
		$images_url = $images_url . '!w' . $width . '_h' . $height . '.' . $ext;
	}
	return $images_url;
}
/**
 * 生成短KEY
 * @param  [type] $text [description]
 * @return [type]       [description]
 */
function short_key($text){
	$crc32_url = crc32($text);
	$result    = sprintf("%u", $crc32_url);
	$short_key   = '';
	while($result > 0){
		$s = $result % 62;
		if($s > 35){
			$s = chr($s + 61);
		} elseif($s > 9 && $s <= 35){
			$s = chr($s + 55);
		}
		$short_key .= $s;
		$result  = floor($result / 62);
	}
	
	return $short_key;
}
